package com.doit.demo02;

public class test02 {
    static volatile boolean flag = true;
    static int num = 0;
    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("进程开始");
                while(flag)
                {
                    num++;
                }
                System.out.println("未修改flag"+(num++));
            }
        }).start();
Thread.sleep(1000);
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (flag)
                {
                    System.out.println("修改flag,结束");
                    flag=false;
                }

            }
        }).start();
    }
}
